package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * @author zhangfujing
 * @date 2024/3/13 22:00
 */
@AllArgsConstructor
@Slf4j
public class DictListener extends AnalysisEventListener<DictEeVo> {
    //这个监听器官方不建议交给spring进行关系，所以需要操作数据库的时候建议使用构造函数传递过来
    private DictMapper dictMapper;
    //一行一行读取
    @Override
    public void invoke(DictEeVo data, AnalysisContext context) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(data,dict);
        dictMapper.insert(dict);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("读取结束！");
    }
}
